package com.addressbook.fw;

import java.util.List;

import org.hibernate.StatelessSession;

public class HibernateHelper extends HelperBase {

	public HibernateHelper(ApplicationManager manager) {
		super(manager);
	}

	public String getLastGroupId() {
		StatelessSession session = HibernateUtil.getSessionFactory().openStatelessSession();
		session.beginTransaction();
		return session.createQuery("SELECT MAX(id) FROM GroupObject").uniqueResult().toString();
	}

	public Groups getGroups() {
		StatelessSession session = HibernateUtil.getSessionFactory().openStatelessSession();
		session.beginTransaction();
		return new Groups((List<GroupObject>) session.createQuery("FROM GroupObject").list());
	}
}
